<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta charset="utf-8" />
<meta name="description" content="Mailbox with some customizations as described in docs" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
<%@ include file="/include/main_include.jsp"%>
</head>
<body class="easyui-layout">
<!-- 左部分 -->
	<div data-options="region:'west',title:'商家列表',split:true" style="width: 17%;">
		<div data-options="region:'north',border:false" style="height: 40px;">
				<div class="input-group">
							<input id="businessName" name="businessName"  type="text" class="form-control search-query"  placeholder="这里输入要查询商家名称">
							<span class="input-group-btn">
								<button type="button" class="btn btn-success btn-sm"  onclick="searchname()">
									<span class="ace-icon fa fa-search icon-on-right bigger-110"></span>
									搜索
								</button>
							</span>
					</div>
		</div>
		<div data-options="region:'center',border:false" style="height: 94.7%;">
			<table id="business_table"></table>
		</div>
	</div>

<!-- 右部分 -->
	<div data-options="region:'center',title:'订单列表',split:true" style="width: 80%; height: 100%;">
		<div data-options="region:'north',border:false" style="height:42px;">
			<div class="grsun-toolbar">
					<button type="button" id="search" class="btn btn btn-toolbar btn-white btn-info no-border auth-hidden">
						<i class="ace-icon fa fa-search green bigger"></i>
						查询
					</button>
			</div>
		</div>
		<div data-options="region:'center',border:false" style="height: 94.7%;">
			<table id="data_table"></table>
		</div>  
	</div>
	<script type="text/javascript">
		var searchParams;
		$(function(){
			//添加按钮事件
			$('#add').on('click', function() {
				openedit('');
			});
			//修改按钮事件
			$('#edit').on('click', function() {
				var node = dataTable.datagrid('getSelected');
				if (node) {
					openedit(node.orderId);
				} else {
					layer.msg('请选择一条数据！', {
						time : 1000
					})
				}
			});
			//删除按钮事件
			$('#item').on('click', function() {
				item();
			});
			//查询按钮事件
			$('#search').on('click', function() {
				opensearch();
			});
		});
		var dataTable;
		var businessTable;
		$(function() {
			//Table表格数据源
			dataTable= $('#data_table').datagrid(BasicData.createDatagrid({  
				frozenColumns:[[
					{field:'ck',checkbox:true},
					{title:'orderId',field:'orderId',hidden:true}
				]],
				columns:[[
					{field:'status',title:'状态',width:'10%',sortable:true,align:'center',formatter:function(value,row,index){ if(value==1){return '提现完成'}else{return '提现中'} }}, 
					{field:'businessName',title:'商家名称',width:'10%',sortable:true,align:'center'},
					{field:'userBusinessName',title:'提现人',width:'10%',sortable:true,align:'center'},
					{field:'withdrawAmount',title:'提现金额',width:'10%',sortable:true,align:'center'},
					{field:'estimateAmount',title:'预计到账金额',width:'10%',sortable:true,align:'center'},
					{field:'poundage',title:'手续费',width:'10%',sortable:true,align:'center'},
					{field:'amount',title:'实际到账金额',width:'10%',sortable:true,align:'center'},
					{field:'serviceAmount',title:'服务费',width:'10%',sortable:true,align:'center'},
					{field:'bank',title:'银行',width:'10%',sortable:true,align:'center'},
					{field:'bankBranch',title:'支行',width:'10%',sortable:true,align:'center'},
					{field:'bankCode',title:'银行卡',width:'10%',sortable:true,align:'center'},
					{field:'bankUser',title:'开户人',width:'10%',sortable:true,align:'center'},
					{field:'addTime',title:'下单时间',width:'10%',sortable:true,align:'center',formatter:function(value,row,index){ return timestampToTime(value);  }}
				]],
				onClickRow:function(rowIndex, rowData){
					
				}
			}));  
			refresh('');
		})
		function searchname() {
			var a = $('#businessName').val()
			refresh(a);
			
		}
		// Table表格数据源
		function refresh(aa) {
			businessTable = $('#business_table').datagrid(BasicData.createDatagrid({
				url : rootpath + '/hhBusiness/list.do?name=' + aa,
				checkOnSelect : true,
				singleSelect : true,
				selectOnCheck : true,
				frozenColumns : [ [ { field : 'ck', checkbox : false, hidden:true },
					{ title : 'businessId', field : 'businessId', hidden : true } ] ],
				columns : [ [ { field : 'name', title : '商家名称', width : '97%', sortable : true, align : 'center' },
				{ field : 'phone', title : '电话', width : '12%', hidden : true },
				{ field : 'status', title : '是否禁用', hidden : true ,formatter:function(value,row,index){
					if(value==0){
						return "否";
					}else{
						return "是";
					}
				   }}, 
				{ field : 'addTime', title : '创建时间', hidden : true,formatter:function(value,row,index){
		        	return timestampToTime(value);
				   }
				} ] ],
				onDblClickRow : function(rowIndex, rowData) {
				},
				onClickRow : function(index, row) {
					dataTable.datagrid({
						url : rootpath + '/hhWithdraw/list.do?businessId=' + row.businessId
					});
				}
			}));
		}
		
		
		//打开查询窗体
		function opensearch(){
			layer.open({
				title : '查询条件',
				type : 2,
				btn : ['查询','重置'],
				yes : function(index,layero) {
					var iframeWin = window[layero.find('iframe')[0]['name']];
					searchParams = iframeWin.$("#searchForm").serialize();
					var newparam = iframeWin.$("#searchForm").serializeJSON();
					$.extend(newparam,dataTable.queryParams);
					$('#data_table').datagrid('load',newparam);
					layer.close(index);
				},
				btn2 : function(index, layero) {
					var iframeWin = window[layero.find('iframe')[0]['name']];
					iframeWin.$("#searchForm").form("clear");
					return false;
				},
				area : [ '80%', '80%' ],
				content : rootpath + '/hhWithdraw/toSearch.do?'+searchParams
			});
		}
		//编辑打开窗体
		function openedit(orderId){
			layer.open({
				title : '信息',
				type : 2,
				btn : ['关闭'],
				btn2 : function(index, layero) {
				},
				area : [ '80%', '80%' ],
				content : rootpath + '/hhOrder/toEdit.do?orderId='+orderId
			});
		}
		//删除
		function item() {
			var node = dataTable.datagrid('getSelected');
			if (node) {
					layer.open({
						title : '明细',
						type : 2,
						btn : ['关闭'],
						btn2 : function(index, layero) {
							var iframeWin = window[layero.find('iframe')[0]['name']];
							iframeWin.$("#searchForm").form("clear");
							return false;
						},
						area : [ '80%', '80%' ],
						content : rootpath + '/hhOrderFood/toList.do?orderId='+node.orderId
					});
			}
		}
	</script>
</body>
</html>